package com.wzgl.core.utils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.collections.map.HashedMap;

import com.jfinal.plugin.activerecord.Record;

public class CommonUtils {
	/** 默认的格式化方式 */
	private static final String defaultFormat = "yyyy-MM-dd HH:mm:ss";

	public static String getDate() {
		SimpleDateFormat dateFormat = new SimpleDateFormat(
				"yyyy-MM-dd HH:mm:ss");
		Date currentDate = new Date();
		String formatCurrentDate = dateFormat.format(currentDate).toString();

		return formatCurrentDate;
	}

	public static String getCurrentDate() {
		String format = "yyyy-MM-dd";
		Date date = new Date();
		date.setTime(System.currentTimeMillis());
		if (format == null || "".equals(format.trim())) {
			format = defaultFormat;
		}
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		return sdf.format(date);
	}

	public static String getCurrentTime() {
		String format = "yyyyMMddHHmmss";
		Date date = new Date();
		date.setTime(System.currentTimeMillis());
		if (format == null || "".equals(format.trim())) {
			format = defaultFormat;
		}
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		return sdf.format(date);
	}
	
	public static Map get(Map<String, String[]> map){
		Map r = new HashMap<String, String>();
		for (Map.Entry<String, String[]> entry : map.entrySet()) { 
			String key = entry.getKey();
			Object value = entry.getValue();
			String val = null;
			if (value != null && ((String[])value)[0] !=null && !"".equals(((String[])value)[0])) {
				val = ((String[])value)[0];
				r.put(key, val); 
			}
		}  
		return r;
	}
}
